layui.define(["form","layer","jquery"],function(exports){
    var form = layui.form,
    layer = parent.layer === undefined ? layui.layer : top.layer,
    $ = layui.jquery,
    mframe = {
    	//获取复选框的值
    	getCheckBoxVal : function(name) {
    		var checkeds = "";
    	    $('input:checkbox[name="' + name + '"]:checked').each(function(i) {
    	        if (0 == i) {
    	        	checkeds = $(this).val();
    	        } else {
    	        	checkeds += ("," + $(this).val());
    	        }
    	    });
    	    return checkeds;
        },
        addOrUpdate:function(url,title){
        	var height = ($(window).height() - 150)
            var index = layui.layer.open({
                title : title,
                type : 2,
                fix: false,
                content : url,
                area: ['800px',height+'px'],
            })
        },
        remove:function(ids,url,tableIns){
            layer.confirm('确定删除此内容？',{icon:3, title:'提示信息'},function(index){
            	var index = layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        	    $.ajax( {
        	        url: url,
        	        type: "post",
        	        dataType: "json",
        	        data: { "ids":ids },
        	        success: function(result) {
        	        	layer.close(index);
    	        		layer.msg(result.msg);
        	        	tableIns.reload();
        	        }
        	    })
            });
        },
        removeAll:function(table,url,tableIns,id){
            var checkStatus = table.checkStatus('layui-table'),
            data = checkStatus.data,
            ids = [];
	        if(data.length > 0) {
	            for (var i in data) {
	            	ids.push(data[i][id]);
	            }
	            layer.confirm('确定删除选中的内容？', {icon: 3, title: '提示信息'}, function (index) {
	            	var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
	        	    $.ajax( {
	        	        url: url,
	        	        type: "post",
	        	        dataType: "json",
	        	        data: { "ids": ids.join() },
	        	        success: function(result) {
	        	        	layer.close(index);
	    	        		layer.msg(result.msg);
	        	        	tableIns.reload();
	        	        }
	        	    })
	            })
	        }else{
	            layer.msg("请选择需要删除的内容");
	        }
        },
        Dic:{
        	getDicList:function(dataType){
        		var data = "";
        		$.ajax( {
        	        url: ctx+"system/dict/data/getType",
        	        type: "post",
        	        dataType: "json",
        	        data: { "dictType": dataType },
        	        async:false,
        	        success: function(result) {
        	        	data = result;
        	        }
        	    })
        	    return data;
        	},
        	getDictValue:function(datas, value){
        		var actions = [];
                $.each(datas, function(index, dict) {
                    if (dict.dictValue == value) {
                    	actions.push("<span class='badge badge-" + dict.listClass + "'>" + dict.dictLabel + "</span>");
                        return false;
                    }
                });
                return actions.join('');
            }
        },
        Tree:{
        	getCheckedNodes:function(tree){
        		var nodes = tree.getCheckedNodes(true);
        		return $.map(nodes, function (row) {
        	        return row['id'];
        	    }).join();
        	}
        }
        
    };
    exports("mframe",mframe);
})